<?php
session_start ();

$_SESSION ['pathway'] = '.';
$_SESSION ['pathway_js'] = '';

if (isset ( $_SESSION ['authentification'] ) and $_SESSION ['authentification'] == '1' and isset ( $_SESSION ['id'] )) {
	
	if (isset ( $_GET ['logout'] ) && $_GET ['logout'] == 'true') { // logout
		$_GET = array ();
		$_POST = array ();
		$_SESSION = array ();
		
		$handle = opendir ( "./tmp/" );
		while ( false !== ($fichier = readdir ( $handle )) ) {
			if (($fichier != ".") && ($fichier != "..")) {
				unlink ( "./tmp/" . $fichier );
			}
		}
		if (isset ( $_SESSION )) {
			session_destroy ();
		}
		include ("formulaire_identification.php");
	} else { // authentifié il y a plusieurs pages ago
		header ( 'Location: ./start.php' );
	}
} elseif (isset ( $_POST ['id'] ) and $_POST ['id'] != '0' and $_POST ['id'] != '') {
	
	require_once ("./requetes/identification.php");
	
	if (isset ( $authentification ) and $authentification == '1') { // authentification ok
		$_SESSION = array ();
		$_SESSION ['authentification'] = '1';
		$_SESSION ['id'] = $_POST ['id'];
		$_SESSION ['code1'] = '';
		$_SESSION ['code2'] = '';
		$_SESSION ['code3'] = '';
		$_SESSION ['code4'] = '';
		$_SESSION ['code5'] = '';
		$_SESSION ['user'] = '';
		$_SESSION ['gene'] = '';
		$_SESSION ['diagnostic'] = '';
		$_SESSION ['status'] = '';
		$_SESSION ['validation'] = '';
		
		echo "<script>window.location.href=\"./start.php\"</script>";
	} else { // authentification foirée
		include ("formulaire_identification.php");
	}
} else {
	include ("formulaire_identification.php"); // on vient d'arriver
}

echo "<p><footer>SPATAX &copy; 2011 UMR_S975<br />";

echo "Last update 2012-06-20</footer></p>";
echo "</body>";
echo "</html>";

?>
